package xyz.molzhao.alink.api;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import xyz.molzhao.alink.api.request.StorageContextRequest;
import xyz.molzhao.alink.api.response.StorageContextResponse;
import xyz.molzhao.alink.domain.StorageContext;
import xyz.molzhao.alink.service.StorageFactory;

import javax.annotation.Resource;

@RestController
public class AlinkController {
    @Resource
    private StorageFactory storageFactory;

    @PostMapping("/upload")
    public StorageContextResponse upload(MultipartFile file, String type) {
        return StorageContextResponse.builder()
                .url(storageFactory.getStorageService(type).upload(BeanUtil.toBean(StorageContextRequest.defaultRequest(file), StorageContext.class))).build();
    }
}
